////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_SCRIPTING_SCOPED_VARIABLE_LIST_H__
#define __WN_SCRIPTING_SCOPED_VARIABLE_LIST_H__

#include "WNScripting/inc/WNScriptVariable.h"

#include <deque>

namespace WNScripting {
    struct WNFunctionDecl;

    class WNScopedVariableList {
    public:
        //TODO: Get llvm to push/pop stack info when we enter/leave scope blocks
        //this way we can do nice stack allocations and not break anything C99 style
        // (we dont have to know the size of an allocation at function enter)
        WN_VOID PushVariable(WNScriptVariable _variable);
        WN_VOID PushGlobalVariable(WNScriptVariable _identifier);
        WN_VOID PushScopeBlock(WNScriptingEngineData& _data);
        //the only reason we would choose to NOT clean the stack is if we hit a return somewhere
        //if this is the case, then the stack will already be clean (otherwise it won't get cleaned)
        WN_VOID PopScopeBlock(WNScriptingEngineData& _data, WN_BOOL _cleanStack);

        const WNScriptVariable& GetVariable(WNIdentifierElement);
        WN_VOID PushFunction(WNFunctionDecl* _functionDecl);
        WN_VOID PopFunction();
        WNFunctionDecl* GetCurrentFunction();

    private:
        std::deque<WNScriptVariable> mScopedVariables;
        std::deque<WNFunctionDecl*> mScopedFunctions;
    };
}
#endif // WN_SCOPED_VARIABLE_LIST_H__